import CryptoJS from 'crypto-js';  //引用AES源码js

//解密方法
function Decrypt(key,iv,word) {
    const ivs=CryptoJS.enc.Utf8.parse(iv)
    const keys=CryptoJS.enc.Utf8.parse(key)
    let encryptedHexStr = CryptoJS.enc.Base64.parse(word);
    let srcs = CryptoJS.enc.Base64.stringify(encryptedHexStr);
    let decrypt = CryptoJS.AES.decrypt(srcs, keys, { iv: ivs, mode: CryptoJS.mode.CBC, padding: CryptoJS.pad.ZeroPadding });
    let decryptedStr = decrypt.toString(CryptoJS.enc.Utf8);
    return decryptedStr.toString();
}

//加密方法
function Encrypt(key,iv,word) {
    let srcs = CryptoJS.enc.Utf8.parse(word);
    let encrypted = CryptoJS.AES.encrypt(srcs, key, { iv: iv, mode: CryptoJS.mode.CBC, padding: CryptoJS.pad.Pkcs7 });
    return encrypted.ciphertext.toString().toUpperCase();
}

export default {
    Decrypt ,
    Encrypt
}